#!/usr/bin/env python

import os, sqlite3
import datetime

sql =''' CREATE TABLE %s (    
    id INT AUTO_INCREMENT,    
    title TEXT,    
    content TEXT,    
    posted_on DATETIME,    
    primary key (id)    
);
'''

DB = r'static/db/content'

Table = 'data'

def CreateDB():
    #print DB
    conn = sqlite3.connect(DB)
    c = conn.cursor()
    c.execute(sql%(Table))
    conn.close()
    return

def new_post(title, content):
    conn = sqlite3.connect(DB)
    mydb = conn.cursor()
    sql = '''insert into %s(title,content) values('%s','%s')'''
    mydb.execute(sql%(Table,title,content))
    conn.commit()
    conn.close()
    return

def get_content():
    #print 'Enter'
    result = []
    conn = sqlite3.connect(DB)
    mydb = conn.cursor()
    sql = 'select title,content from %s'%(Table)
    #print sql
    mydb.execute(sql)
    for item in mydb:
        #print 'Select:',item
        result.append(item)
    conn.close()
    return result
